package com.example.zhaoyulu.yunzhiapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.network.getRetrofitService;
import com.example.network.javaBeans.Book;
import com.example.network.javaBeans.loginBean;
import com.example.network.javaBeans.yzjyinfo;
import com.example.network.javaBeans.yzjystudent;
import com.example.zhaoyulu.yunzhiapp.zylUtils.staticInfo;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class LoginActivity extends zylBaseActivity {

    EditText login_getId;
    EditText login_getPassWord;
    Button login_getIntoApp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.activity_login);

        init();

        regist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(LoginActivity.this, registActivity.class);
                startActivity(intent);
            }
        });



        login_getIntoApp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

//                if (response.body().getFlag().equals("201")) {
//
//                }else{
//
//                }



                getRetrofitService.getService().getYzjystudent("log", login_getId.getText().toString(), login_getPassWord.getText().toString())
                        .enqueue(new Callback<List<yzjystudent>>() {
                            @Override
                            public void onResponse(Call<List<yzjystudent>> call, Response<List<yzjystudent>> response) {
                                if(response.body().get(0).getFlag().equals("201")){
                                    Intent intent = new Intent();
                                    intent.setClass(LoginActivity.this, MainActivity.class);
                                    startActivity(intent);
                                    finish();;
                                }
                            }

                            @Override
                            public void onFailure(Call<List<yzjystudent>> call, Throwable t) {

                            }
                        });





            }
        });
    }
    TextView regist;

    public void init() {
        login_getId = findViewById(R.id.login_getId);
        login_getPassWord = findViewById(R.id.login_getPassWord);
        login_getIntoApp = findViewById(R.id.login_getIntoApp);
        regist= findViewById(R.id.regist);
    }
}
